package erp.server.message.controller;

import erp.server.base.response.JsonResult;
import erp.server.base.response.StatusCode;
import erp.server.message.pojo.dto.MessageSaveDTO;
import erp.server.message.pojo.vo.MessageVO;
import erp.server.message.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 消息管理
 */
@Slf4j
@RestController
@RequestMapping("/isms/message")
public class MessageController {
    @Autowired
    MessageService messageService;

    /**
     * 保存消息
     * @return 操作成功
     */
    @PostMapping("/save")
    public JsonResult saveMessage(MessageSaveDTO messageSaveDTO) {
        log.debug("保存消息：MessageDTO: {}", messageSaveDTO);
        messageService.saveMessage(messageSaveDTO);
        return new JsonResult(StatusCode.OPERATION_MESSAGE_SUCCESS);
    }

    /**
     * 发送消息
     * @param messageId 要发送的消息id
     * @return 操作结果状态
     */
    @GetMapping("/send/{messageId}")
    public JsonResult sendMessage(@PathVariable("messageId") Long messageId){
        log.debug("发送消息 MessageId: {}", messageId);
        messageService.sendMessage(messageId);
        return new JsonResult(StatusCode.OPERATION_MESSAGE_SUCCESS);
    }

    /**
     * 获取消息详情
     * @param messageId 该消息id
     * @return 消息详情
     */
    @GetMapping("/message_detail/{messageId}")
    public JsonResult getMessageDetail(@PathVariable("messageId") Long messageId){
        log.debug("获取消息详情页 MessageId: {}", messageId);
        MessageVO messageVO = messageService.selectMessageDetailById(messageId);
        return new JsonResult(StatusCode.OPERATION_MESSAGE_SUCCESS,messageVO);
    }






}








